import axios from 'axios'
import commonUrl from '../common/js/commonUrl'
import {loadUserId, loadVillageId} from '../common/js/cache'
import qs from 'qs'

// 选举报名列表
export function singList() {
  const url = `${commonUrl.apihost}index.php/home/signform/index`
  const data = {
    areas_id: loadVillageId(),
    user_id: loadUserId()
  }
  return axios({
    method: 'post',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 选举报名的接口
export function candRegist(id, name, sex, house, areas, political, profession, education, profile, commitment, campaign, fee, birth, phone, reason, headImage, img) {
  const url = `${commonUrl.apihost}/index.php/home/signperson/addSign`
  const data = {
    areas_id: loadVillageId(),
    sign_id: id,
    user_id: loadUserId(),
    name: name,
    sex: sex,
    house: house,
    areas: areas,
    political: political,
    profession: profession,
    education: education,
    profile: profile,
    commitment: commitment,
    campaign: campaign,
    fee_status: fee,
    birth: birth,
    phone: phone,
    reason: reason,
    head_img: headImage,
    img: img
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}
